package top.whk0710.algorithms.sort;

public class MyQuickSort {

	public static void main(String[] args) {

		int[] array = {8,3,2,4,5,1,6,7};
		sort(array,0,array.length-1);
		for(int i : array){
			System.out.println(i);
		}
	}

	public static void sort(int[] arr, int low, int high){
		if(low >= high) return;
		
		int i = low;
		int j = high;
		int key = arr[low];
		
		while(i < j){
			while(i < j && arr[j] >= key) j--;
			if(i < j){
				arr[i] = arr[j]; 
				i++;
			}
			
			while(i < j && arr[j] < key) i++;
			if(i < j){
				arr[j] = arr[i]; 
				j--;
			}
		}
		
		arr[i] = key;
		sort(arr, low, i-1);
		sort(arr, i+1, high);
	}
}
